<?php

class Control_Gm_getServerListByGameAjax
{
    function getServerListByGameAjax()
    {

        $game = MooForm::request('game');

        //转换游戏名为英文
        $gameLangConf = MooConfig::get('game_lang.zh_en');
        if ($gameLangConf[$game]) {
            $game = $gameLangConf[$game];
        }

        $getServersUrl = MooConfig::get('main.url.fetch_server');
        $url = $getServersUrl . "?game=" . $game;

        $res = MooUtil::curl_send($url);

        $resArr = MooJson::decode($res, true);

        $resData = array();
        if ($resArr) {
            foreach ($resArr as $key => $val) {
                $arr['id'] = $key;
                $arr['platform'] = $val['platform'];
                $arr['serverId'] = $val['server'];
                $arr['server'] = $val['platform'] . "-" . $val['server'];
                $arr['url'] = $val['ip'] . ":" . $val['script_port'];
                $resData[$arr['server']] = $arr;
            }
        }

        MooArray::tdSort($resData, "platform", SORT_ASC, "serverId", SORT_ASC);

        $rs = MooJson::encode($resData);
        exit($rs);

    }

}